import 'package:flutter/material.dart';
import 'package:flutter_mall_app/pages/home_page.dart';
import 'package:flutter_mall_app/pages/member_center.dart';
import 'package:flutter_mall_app/pages/product/prooduct_list.dart';
import 'package:flutter_mall_app/pages/shopping_cart/shopping_cart.dart';
import 'package:flutter_mall_app/provide/current_Index_provide.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

class IndexPage extends StatelessWidget {
  List<BottomNavigationBarItem> bottomNavigationBarItemList = [
    BottomNavigationBarItem(
      icon: Icon(Icons.home),
      title: Text('首页'),
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.format_list_bulleted),
      title: Text('分类'),
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.shopping_cart),
      title: Text('购物车'),
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.account_circle),
      title: Text('我的'),
    ),
  ];

  final List<Widget> tabBodies = [
    HomePage(),
    ProductList(),
    ShoppingCart(),
    MemberCenter(),
  ];

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    return Provide<CurrentIndexProvide>(builder: (context, child, val) {
      int currentIndex = Provide.value<CurrentIndexProvide>(context).currentIndex;
      return Scaffold(
        backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          fixedColor: Colors.red,
          selectedFontSize: 12,
          unselectedItemColor: Colors.grey,
          currentIndex: currentIndex,
          items: bottomNavigationBarItemList,
          onTap: (index) {
            Provide.value<CurrentIndexProvide>(context).changeIndex(index);
          },
        ),
        body: IndexedStack(index: currentIndex, children: tabBodies),
      );
    });
  }
}

//class IndexPage extends StatefulWidget {
//  @override
//  _IndexPageState createState() => _IndexPageState();
//}
//
//class _IndexPageState extends State<IndexPage> {
//
//  List<BottomNavigationBarItem> bottomNavigationBarItemList = [
//    BottomNavigationBarItem(
//      icon: Icon(Icons.home),
//      title: Text('首页'),
//    ),
//    BottomNavigationBarItem(
//      icon: Icon(Icons.format_list_bulleted),
//      title: Text('分类'),
//    ),
//    BottomNavigationBarItem(
//      icon: Icon(Icons.shopping_cart),
//      title: Text('购物车'),
//    ),
//    BottomNavigationBarItem(
//      icon: Icon(Icons.account_circle),
//      title: Text('我的'),
//    ),
//  ];
//
//  int _currentIndex = 0;
//  PageController _pageController;
//
//  @override
//  void initState() {
//    super.initState();
//    _pageController = PageController(
//      initialPage: this._currentIndex,
//      keepPage: true,
//    );
//  }
//
//  @override
//  Widget build(BuildContext context) {
//    ScreenUtil.instance = ScreenUtil(width: 750,height:1334 )..init(context);
////    debugPrint("设备的像素密度:${ScreenUtil.pixelRatio}");
////    debugPrint("设备的高:${ScreenUtil.screenHeight}");
////    debugPrint("设备的宽:${ScreenUtil.screenWidth}");
//    return Scaffold(
//      body: PageView(
//        children: <Widget>[
//          HomePage(),
//          ProductList(),
//          ShoppingCart(),
//          MemberCenter(),
//        ],
//        controller: _pageController,
//        physics: NeverScrollableScrollPhysics(),
//        onPageChanged: (index) {
//          setState(() {
//            _currentIndex = index;
//          });
//        },
//      ),
//      bottomNavigationBar: BottomNavigationBar(
//        items: bottomNavigationBarItemList,
//        type: BottomNavigationBarType.fixed,
//        currentIndex: _currentIndex,
//        fixedColor: Colors.red,
//        selectedFontSize: 12,
//        unselectedItemColor: Colors.grey,
//        onTap: (index) {
//         _pageController.animateToPage(index,duration: Duration(milliseconds: 300), curve:Curves.ease);
//        },
//      ),
//    );
//  }
//
//  @override
//  void dispose() {
//    _pageController.dispose();
//    super.dispose();
//  }
//}
